package com.smz.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smz.entity.TCargo;
import com.smz.service.TCargoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
public class TCargoController {

    @Autowired
    private TCargoService tCargoService;




    @ApiOperation("分页查询")
    @RequestMapping(value = "/tCargo/page",method = RequestMethod.GET)
    public ResponseEntity<Page<TCargo>> pageTCargo(@RequestParam(value = "current",defaultValue = "1")Integer current,@RequestParam(value = "rows",defaultValue = "1")Integer rows
                                                    ,@RequestParam(value = "tShelvesNo")Integer tShelvesNo,@RequestParam("damId") Integer damId
                                                   ,@RequestParam("wareId") Integer wareId){
        Page<TCargo> pageTCargo = tCargoService.findPageTCargo(current, rows,tShelvesNo,damId,wareId);
        return ResponseEntity.ok(pageTCargo);
    }

    @ApiOperation("分页搜索")
    @RequestMapping(value = "/tCargo/page/search",method = RequestMethod.GET)
    public ResponseEntity<Page<TCargo>> pageTCargoSearch(@RequestParam(value = "current",defaultValue = "1")Integer current,@RequestParam(value = "rows",defaultValue = "1")Integer rows
            ,@RequestParam(value = "shelvesNo")String shelvesNo,@RequestParam("CargoNo") String cargoNo
            ,@RequestParam("CargoStatus") String cargoStatus){
        Page<TCargo> pageTCargo = tCargoService.findPageTCargoSearch(current, rows,"".equals(shelvesNo)?null:Integer.valueOf(shelvesNo),"".equals(cargoNo)?null:Integer.valueOf(cargoNo),"".equals(cargoStatus)?null:Integer.valueOf(cargoStatus));
        return ResponseEntity.ok(pageTCargo);
    }

    @ApiOperation("添加仓位")
    @RequestMapping(value = "/tCargo",method = RequestMethod.POST)
    public String addTCargo(@RequestBody TCargo tCargo){
        tCargoService.save(tCargo);
        return "ok";
    }

    @ApiOperation("更新仓位")
    @RequestMapping(value = "/tCargo",method = RequestMethod.PUT)
    public String modifyTCargo(@RequestBody TCargo tCargo){
        tCargoService.update(tCargo,new QueryWrapper<TCargo>().lambda().eq(TCargo::getId,tCargo.getId()));
        return "ok";
    }


}
